package com.baizhi.jishi.service.impl;

import com.baizhi.jishi.dao.TriageDao;
import com.baizhi.jishi.entity.Triage;
import com.baizhi.jishi.entity.User;
import com.baizhi.jishi.service.TriageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class TriageServiceImpl implements TriageService {
    @Autowired
    private TriageDao triageDao;
    @Override
    public Map add(Triage triage, HttpSession session) {
        Map map = new HashMap();
        User user = (User) session.getAttribute("user");
        triage.setUser(user);
        int add = triageDao.add(triage);
        if (add>0){
            map.put("addResult",true);
        }else {
            map.put("addResult",false);
        }
        return map;
    }

    @Override
    public Map showPage(int page, int limit,int id) {
        Map map = new HashMap();
        page = page-1;
        List<Triage> triages = triageDao.showPage(page, limit, id);
        int count = triageDao.getCount(id);
        //System.out.println(triages);
        map.put("count",count);
        map.put("data",triages);
        map.put("code",0);
        map.put("msg","");
        return map;
    }

    @Override
    public Map selectOne(int id) {
        Map map = new HashMap();
        Triage triage = triageDao.selectOne(id);
        map.put("triage",triage);
        return map;
    }

    @Override
    public Map update(Triage triage) {
        Map map = new HashMap();
        System.out.println(triage);
        int update = triageDao.update(triage);
        if (update>0){
            map.put("Result",true);
        }else {
            map.put("Result",false);
        }
        return map;
    }
}
